home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / sgml / sgml2latex-format.1.3.tar.Z / sgml2latex-format.1.3.tar / rep / addrlst / sort / sortaddr.awk < prev   
Text File  |  1993-07-23  |  2KB  |  72 lines

  1.  
  2. # author : Tom Gordon
  3. # date   : 28 July 92
  4.  
  5. # AWK script for generating an SGML address list from a AWK database
  6. # which presumably has been sorted.  The format of the AWK database
  7. # is presumed to have the following format.  Records are separated by
  8. # new lines.  Fields are separated by tabs.   The fields are arranged 
  9. # in a sequence of (tag, value) pairs.  There may be multiple "line" 
  10. # tags.   
  11.  
  12. BEGIN { FS="\t"
  13.         print "<!doctype addrlst public \"-//GMD//DTD addrlst//EN\">"
  14.     print "<addrlst>"
  15.     printf "\n" }
  16.  
  17.       { # intialize the array
  18.     r["alias"] = ""
  19.         r["title"] = ""
  20.         r["name"] = ""
  21.         r["lines"] = ""
  22.     r["pobox"] = ""
  23.     r["street"] = ""
  24.     r["city"] = ""
  25.     r["country"] = ""
  26.         r["tel"] = ""
  27.     r["telex"] = ""
  28.         r["fax"] = ""
  29.     r["email"] = ""
  30.     r["lists"] = ""  
  31.     r["date"] = ""
  32.         r["notes"] = ""
  33.  
  34.         for (i = 1; i < (NF-1); i += 2) {  # load the array
  35.             if ($i == "line") {  # pack all lines into the lines field
  36.           if (r["lines"] == "") {
  37.             r["lines"] = $(i+1) 
  38.           } else {
  39.             r["lines"] = r["lines"] "\\" $(i+1)
  40.           }
  41.         } else {
  42.           r[$i] = $(i+1)
  43.         }
  44.           }
  45.     print "<entry>"
  46.     printf ("<alias>\t\t%s\n", r["alias"])
  47.            if (r["title"] != "") { printf ("<title>\t\t%s\n", r["title"]) }
  48.     printf ("<name>\t\t%s\n", r["name"])
  49.  
  50.            if (r["lines"] != "") { 
  51.             n = split(r["lines"], a, "\\")
  52.             for (i = 1; i <= n; i++) {
  53.                    printf ("<line>\t\t%s\n", a[i]) 
  54.         }
  55.     }
  56.  
  57.         if (r["pobox"] != "") { printf ("<pobox>\t\t%s\n", r["pobox"]) }
  58.            if (r["street"] != "") { printf ("<street>\t%s\n", r["street"]) }
  59.            if (r["city"] != "") { printf ("<city>\t\t%s\n", r["city"]) }
  60.            if (r["country"] != "") { printf ("<country>\t%s\n", r["country"]) }
  61.            if (r["tel"] != "") { printf ("<tel>\t\t%s\n", r["tel"]) }
  62.            if (r["telex"] != "") { printf ("<telex>\t\t%s\n", r["telex"]) }
  63.            if (r["fax"] != "") { printf ("<fax>\t\t%s\n", r["fax"]) }
  64.            if (r["email"] != "") { printf ("<email>\t\t%s\n", r["email"]) }
  65.            if (r["lists"] != "") { printf ("<lists>\t\t%s\n", r["lists"]) }
  66.            if (r["date"] != "") { printf ("<date>\t\t%s\n", r["date"]) }
  67.            if (r["notes"] != "") { printf ("<notes>\t\t%s\n", r["notes"]) }
  68.     printf "\n"
  69.       }
  70. END   { print "</addrlst>" }
  71.  
  72.